package com.drotposta.unitils;

import java.io.File;
import java.util.Properties;
import org.unitils.core.Module;
import org.unitils.core.TestListener;

/**
 *
 * @author elek
 */
public class UnitilsEjbModule implements Module {

    private static final String CONFIG_PREFIX = "com.drotposta.ejbmodule";
    private static final String CONFIG_PERSISTENCEUNIT = CONFIG_PREFIX + ".persistenceUnit";
    private static final String CONFIG_EJBLOCATION = CONFIG_PREFIX + ".ejblocations";
    public String persistenceUnit;

    public void init(Properties configuration) {
        persistenceUnit = configuration.getProperty(CONFIG_PERSISTENCEUNIT);
        String ejbLocation = configuration.getProperty(CONFIG_EJBLOCATION, "build/test/classes:build/classes:target/classes");
        String[] locations = ejbLocation.trim().split(":");
        for (String path : locations) {
            EJBClassRegister.getInstance().load(new File(path));
        }

    }

    public void afterInit() {
        //noop
    }

    public TestListener getTestListener() {
        return new UnitilsEjbModuleListener(persistenceUnit);
    }
}
